<div class="row actions">
    <div class="col-md-12">
        <div class="pull-left">
            <button ng-if="user.hasPermission($state.name.split('.')[0],'create')" class="btn btn-success" ng-click="openCreateItemModal()">
                <i class="mdi mdi-plus"></i>
                Create upstream
            </button>
            <button class="btn btn-link btn-danger" ng-click="openAlertsListModal()">
                <i class="mdi mdi-bell-outline"></i>&nbsp;
                Alert triggers&nbsp;
                <span class="badge">{{alertsCount}}</span>
            </button>
        </div>
        <list-search
                class="pull-right"
                data-filters="filters"
                data-options="itemsPerPageOptions"
                data-items="itemsPerPage"
        ></list-search>
    </div>
</div>

<konga-loader ng-if="loading && !items.length"></konga-loader>
<div class="row" ng-if="!loading || items.length">
    <div class="col-md-12">
        <div class="table-responsive">
            <table class="table table-hover table-striped">
                <tr>
                    <th width="{{item.width}}" class="text-nowrap"
                        data-ng-repeat="item in titleItems | filter:titleFilter"
                    >
                        <a
                                class="clickable"
                                data-ng-show="item.column"
                                data-ng-click="changeSort(item)"
                                data-ng-bind-html="item.title.toUpperCase()"
                        ></a>
                        <span
                                data-ng-show="!item.column"
                                data-ng-bind-html="item.title.toUpperCase()"
                        ></span>
                        <input data-ng-if="item.checkbox" type="checkbox" data-ng-model="globalCheck.isAllChecked"/>
                        <i class="mdi"
                           data-ng-show="sort.column == item.column"
                           data-ng-class="{'mdi-chevron-down': !sort.direction, 'mdi-chevron-up': sort.direction}"
                        >
                        </i>
                    </th>
                    <th width="1" ng-if="user.hasPermission('upstreams','edit')"></th>
                    <th width="1" ng-if="user.hasPermission('upstreams','delete')"></th>
                </tr>
                <tr dir-paginate="item in items.data | orderBy:sort.column:sort.direction | filter : filters.searchWord | itemsPerPage: itemsPerPage">
                    <td>
                        <raw-view data-item="item"></raw-view>
                    </td>
                    <td>{{item.name || "-"}}</td>
                    <td>{{item.slots || "-"}}</td>
                    <td>{{moment(item.created_at * 1000).format("MMM DD YYYY @HH:mm")}}</td>
                    <td ng-if="user.hasPermission('upstreams','edit')">
                        <a class="btn clickable btn-primary btn-link" data-ui-sref="upstreams.edit({id:item.id})">
                            <i class="mdi mdi-information-outline"></i>
                            details
                        </a>
                    </td>
                    <td ng-if="user.hasPermission('upstreams','delete')">
                        <button type="button" ng-click="deleteItem($index,item)" class="btn btn-danger btn-link">
                            <i class="mdi mdi-delete"></i>
                            Delete
                        </button>
                    </td>
                </tr>

                <tr data-ng-if="items.length === 0 && !loading">
                    <td colspan="100%" class="text-center text-muted">
                        <em>No data found...</em>
                    </td>
                </tr>
                <tr data-ng-if="loading">
                    <td colspan="100%" class="text-center text-muted">
                        <em>Loading upstreams...</em>
                    </td>
                </tr>
            </table>
        </div>

    </div>
    <dir-pagination-controls class="pull-right"></dir-pagination-controls>
</div>

